{% extends "base.html" %}

{% block css %}
    <style>
        .btn-primary:hover {
            color: red;
        }
    </style>
{% endblock %}

{% block nav %}
    {% for object in model_list %}
        <li><a href="{{ object.url }}"><i class="{{ object.icon }}"></i>{{ object.model_name }}</a>
        </li>

    {% endfor %}

{% endblock %}


{% block crumbs %}
    <div class="row">
        <div class="col-md-12">
            <ol class="breadcrumb">
                <li class="active">
                    <a class="this-page" href="{% url 'base:project' %}">定时任务</a>
                </li>
                <li class="active">
                    <a class="this">编辑任务</a>
                </li>
            </ol>

        </div>
    </div>
{% endblock %}

{% block body %}

    <div class="row">
        <div class="col-md-12">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">编辑任务</h3>
                </div>
                <div class="panel-body">
                    {% if permission_error %}
                        <p style="color: red">{{ permission_error }}</p>
                    {% else %}
                        <div class="form-horizontal">
                            <input id="task_id" value={{ periodic.id }} hidden>
                            <input id="page" value={{ page }} hidden>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">任务名称</label>
                                <div class="col-sm-6">
                                    <input type="text" name="task_name" lay-verify="title" autocomplete="off"
                                           id="task_name"
                                           class="form-control" value={{ periodic.name }}>
                                </div>
                                <span style="color: red; font-size: 10px;" id="task_name_error"></span>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">计划列表</label>
                                <a id="getcases" onclick="get_plan()" class="btn btn-primary"><i
                                        class="fa fa-get-pocket"></i>&nbsp;获取计划</a>
                                <div id="list" class="col-sm-10 col-sm-offset-2">
                                    {% for plan in plan_list %}
                                        <label class='checkbox-inline'><input type='checkbox' name='case_id'
                                                                              id="case_id"
                                                                              value="{{ plan.plan_id }}"
                                                                              checked>{{ plan.plan_name }}</label>
                                    {% endfor %}
                                </div>
                                <span style="color: red; font-size: 10px;display: none" id="plan_error"></span>
                            </div>
                            <div class="form-group" style="margin-top: 2%">
                                <label class="col-sm-2 control-label">任务状态</label>
                                <div class="col-sm-6">
                                    {% ifequal periodic.enabled True %}
                                        <div class="col-sm-4 control-label">
                                            <label class="fancy-radio">
                                                <input name="status" value="1" type="radio"
                                                       checked><span><i></i>有效</span>
                                            </label>
                                        </div>
                                    {% else %}
                                        <div class="col-sm-4 control-label">
                                            <label class="fancy-radio">
                                                <input name="status" value="1" type="radio"><span><i></i>有效</span>
                                            </label>
                                        </div>
                                    {% endifequal %}
                                    {% ifequal periodic.enabled False %}
                                        <div class="col-sm-4 control-label">
                                            <label class="fancy-radio">
                                                <input name="status" value="0" type="radio"
                                                       checked><span><i></i>无效</span>
                                            </label>
                                        </div>
                                    {% else %}
                                        <div class="col-sm-4 control-label">
                                            <label class="fancy-radio">
                                                <input name="status" value="0" type="radio"><span><i></i>无效</span>
                                            </label>
                                        </div>
                                    {% endifequal %}
                                </div>
                            </div>
                            <div class="form-group" style="margin-top: 2%">
                                <label class="col-sm-2 control-label">执行时间</label>
                                <div class="col-sm-6">
                                    <div class="col-sm-4 control-label" onclick="execution()">
                                        {% if interval %}
                                            <label class="fancy-radio">
                                                <input name="crontab_time" value="1" type="radio"
                                                       checked><span><i></i>间隔</span>
                                            </label>
                                        {% else %}
                                            <label class="fancy-radio">
                                                <input name="crontab_time" value="1" type="radio"><span><i></i>间隔</span>
                                            </label>
                                        {% endif %}

                                    </div>
                                    <div class="col-sm-4 control-label" onclick="execution()">
                                        {% if crontab %}
                                            <label class="fancy-radio">
                                                <input name="crontab_time" value="2"
                                                       type="radio" checked><span><i></i>Crontab</span>
                                            </label>
                                        {% else %}
                                            <label class="fancy-radio">
                                                <input name="crontab_time" value="2"
                                                       type="radio"><span><i></i>Crontab</span>
                                            </label>
                                        {% endif %}

                                    </div>
                                </div>
                            </div>
                            {% if interval %}
                                <div class="form-group" style="margin-top: 2%;display: block" id="interval_div">
                                    <label class="col-sm-2 control-label"></label>
                                    <div class="col-sm-6">
                                        <div class="col-sm-3 control-label" onclick="custom()">
                                            <label class="fancy-radio">
                                                <input name="task_time" value="1" type="radio"><span><i></i>每   天</span>
                                            </label>
                                        </div>
                                        <div class="col-sm-3 control-label" onclick="custom()">
                                            <label class="fancy-radio">
                                                <input name="task_time" value="2" type="radio"><span><i></i>每   周</span>
                                            </label>
                                        </div>
                                        <div class="col-sm-3 control-label" onclick="custom()">
                                            <label class="fancy-radio">
                                                <input name="task_time" value="3" type="radio"
                                                       id="custom"><span><i></i>自 定 义</span>
                                            </label>
                                        </div>
                                        <div class="col-sm-3 control-label" onclick="custom()">
                                            <label class="fancy-radio">
                                                <input name="task_time" value="4" type="radio"
                                                       id="custom" checked><span><i></i>已设置时间</span>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group" style="display: block" id="interval">
                                    <label class="col-sm-3 control-label"
                                           style="font-size: 12px;font-weight: 100">间隔</label>
                                    <div class="col-sm-6">
                                        <select name="interval_" class="form-control" required="required"
                                                id="interval_">
                                            <option value={{ interval.id }}>{{ interval.every }} {{ interval.period }}/次</option>
                                            {% for interval in interval_list %}
                                                <option value={{ interval.id }}>{{ interval.every }} {{ interval.period }}/次</option>
                                            {% endfor %}
                                        </select>
                                    </div>
                                    <a class="related-widget-wrapper-link change-related" id="change_id_interval"
                                       href="javascript:void(0)" onclick="change_interval()"><img
                                            src="/static/admin/img/icon-changelink.svg" alt="修改"></a>
                                    <span style="color: red; font-size: 10px;display: none" id="interval_error"></span>
                                </div>
                            {% else %}
                                <div class="form-group" style="margin-top: 2%;display: none" id="interval_div">
                                    <label class="col-sm-2 control-label">定时方式</label>
                                    <div class="col-sm-6">
                                        <div class="col-sm-3 control-label" onclick="custom()">
                                            <label class="fancy-radio">
                                                <input name="task_time" value="1" type="radio"
                                                       checked><span><i></i>每   天</span>
                                            </label>
                                        </div>
                                        <div class="col-sm-3 control-label" onclick="custom()">
                                            <label class="fancy-radio">
                                                <input name="task_time" value="2" type="radio"><span><i></i>每   周</span>
                                            </label>
                                        </div>
                                        <div class="col-sm-3 control-label" onclick="custom()">
                                            <label class="fancy-radio">
                                                <input name="task_time" value="3" type="radio"
                                                       id="custom"><span><i></i>自 定 义</span>
                                            </label>
                                        </div>
                                        <div class="col-sm-3 control-label" onclick="custom()">
                                            <label class="fancy-radio">
                                                <input name="task_time" value="4" type="radio"
                                                       id="custom"><span><i></i>已设置时间</span>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group" style="display: none" id="interval">
                                    <label class="col-sm-3 control-label"
                                           style="font-size: 12px;font-weight: 100">间隔</label>
                                    <div class="col-sm-6">
                                        <select name="interval_" class="form-control" required="required"
                                                id="interval_">
                                            {% for interval in interval_list %}
                                                <option value={{ interval.id }}>{{ interval.every }} {{ interval.period }}/次</option>
                                            {% endfor %}
                                        </select>
                                    </div>
                                    <a class="related-widget-wrapper-link change-related" id="change_id_interval"
                                       href="javascript:void(0)" onclick="change_interval()"><img
                                            src="/static/admin/img/icon-changelink.svg" alt="修改"></a>
                                    <span style="color: red; font-size: 10px;display: none" id="interval_error"></span>
                                </div>
                            {% endif %}
                            <div class="form-group" style="display: none" id="set_time">
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Every</label>
                                <div class="col-sm-2">
                                    <input type="number" name="every" class="form-control" required="" id="id_every">
                                </div>
                                <label class="col-sm-1 control-label"
                                       style="font-size: 12px;font-weight: 100">Period</label>
                                <div class="col-sm-3">
                                    <select name="period" required="required" id="id_period" class="form-control">
                                        <option value="" selected="">---------</option>

                                        <option value="days">天</option>

                                        <option value="hours">时</option>

                                        <option value="minutes">分</option>

                                        <option value="seconds">秒</option>

                                        <option value="microseconds">微秒</option>

                                    </select>
                                </div>
                                <span style="color: red; font-size: 10px;display: none" id="every_error"></span>
                            </div>

                            <div class="form-group" style="display: none" id="set_time_interval">
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Every</label>
                                <div class="col-sm-2">
                                    <input type="number" name="every" class="form-control" required="" id="id_every_1">
                                </div>
                                <label class="col-sm-1 control-label"
                                       style="font-size: 12px;font-weight: 100">Period</label>
                                <div class="col-sm-3">
                                    <select name="period" required="required" id="id_period_1" class="form-control">
                                        <option id="id_period_2" selected=""></option>

                                        <option value="days">天</option>

                                        <option value="hours">时</option>

                                        <option value="minutes">分</option>

                                        <option value="seconds">秒</option>

                                        <option value="microseconds">微秒</option>

                                    </select>
                                </div>
                                <span style="color: red; font-size: 10px;display: none" id="every_error_1"></span>
                            </div>
                            {% if crontab %}
                                <div class="form-group" style="display: block;margin-top: 2%" id="crontab_div">
                                    <label class="col-sm-2 control-label">定时方式</label>
                                    <div class="col-sm-6">
                                        <div class="col-sm-3 control-label" onclick="crontab_div()">
                                            <label class="fancy-radio">
                                                <input name="crontab_div_time" value="1" type="radio"
                                                       id="custom"><span><i></i>自 定 义</span>
                                            </label>
                                        </div>
                                        <div class="col-sm-3 control-label" onclick="crontab_div()">
                                            <label class="fancy-radio">
                                                <input name="crontab_div_time" value="2" type="radio"
                                                       id="custom" checked><span><i></i>已设置时间</span>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group" style="display: block" id="set_up_time">
                                    <label class="col-sm-3 control-label"
                                           style="font-size: 12px;font-weight: 100">Crontab：</label>
                                    <div class="col-sm-6">
                                        <select name="crontab_" class="form-control" required="required" id="crontab_">
                                            <option value={{ crontab.id }}>{{ crontab.minute }} {{ crontab.hour }} {{ crontab.day_of_week }} {{ crontab.day_of_month }} {{ crontab.month_of_year }}
                                                (m/h/d/dM/MY)
                                            </option>
                                            {% for crontab in crontab_list %}
                                                <option value={{ crontab.id }}>{{ crontab.minute }} {{ crontab.hour }} {{ crontab.day_of_week }} {{ crontab.day_of_month }} {{ crontab.month_of_year }}
                                                    (m/h/d/dM/MY)
                                                </option>
                                            {% endfor %}
                                        </select>
                                    </div>
                                    <a class="related-widget-wrapper-link change-related" id="change_id_interval"
                                       href="javascript:void(0)" onclick="change_crontab()"><img
                                            src="/static/admin/img/icon-changelink.svg" alt="修改"></a>
                                    <span style="color: red; font-size: 10px;display: none"
                                          id="crontab_time_error"></span>
                                </div>
                            {% else %}
                                <div class="form-group" style="display: none;margin-top: 2%" id="crontab_div">
                                    <label class="col-sm-2 control-label"></label>
                                    <div class="col-sm-6">
                                        <div class="col-sm-3 control-label" onclick="crontab_div()">
                                            <label class="fancy-radio">
                                                <input name="crontab_div_time" value="1" type="radio"
                                                       id="custom"><span><i></i>自 定 义</span>
                                            </label>
                                        </div>
                                        <div class="col-sm-3 control-label" onclick="crontab_div()">
                                            <label class="fancy-radio">
                                                <input name="crontab_div_time" value="2" type="radio"
                                                       id="custom"><span><i></i>已设置时间</span>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group" style="display: none" id="set_up_time">
                                    <label class="col-sm-3 control-label"
                                           style="font-size: 12px;font-weight: 100">Crontab：</label>
                                    <div class="col-sm-6">
                                        <select name="crontab_" class="form-control" required="required" id="crontab_">
                                            {% for crontab in crontab_list %}
                                                <option value={{ crontab.id }}>{{ crontab.minute }} {{ crontab.hour }} {{ crontab.day_of_week }} {{ crontab.day_of_month }} {{ crontab.month_of_year }}
                                                    (m/h/d/dM/MY)
                                                </option>
                                            {% endfor %}
                                        </select>
                                    </div>
                                    <a class="related-widget-wrapper-link change-related" id="change_id_interval"
                                       href="javascript:void(0)" onclick="change_crontab()"><img
                                            src="/static/admin/img/icon-changelink.svg" alt="修改"></a>
                                    <span style="color: red; font-size: 10px;display: none"
                                          id="crontab_time_error"></span>
                                </div>
                            {% endif %}

                            <div class="form-group" style="display: none" id="crontab_minute">
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Minute:</label>
                                <div class="col-sm-8">
                                    <input type="text" name="minute" value="*" class="vTextField" maxlength="64"
                                           required=""
                                           id="id_minute">
                                </div>
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Hour:</label>
                                <div class="col-sm-8">
                                    <input type="text" name="hour" value="*" class="vTextField" maxlength="64"
                                           required=""
                                           id="id_hour">
                                </div>
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Day of week:</label>
                                <div class="col-sm-8">
                                    <input type="text" name="day_of_week" value="*" class="vTextField" maxlength="64"
                                           required="" id="id_day_of_week">
                                </div>
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Day of month:</label>
                                <div class="col-sm-8">
                                    <input type="text" name="day_of_month" value="*" class="vTextField" maxlength="64"
                                           required="" id="id_day_of_month">
                                </div>
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Month of year:</label>
                                <div class="col-sm-8">
                                    <input type="text" name="month_of_year" value="*" class="vTextField" maxlength="64"
                                           required="" id="id_month_of_year">
                                </div>
                            </div>
                            <div class="form-group" style="display: none" id="set_crontab_minute">
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Minute:</label>
                                <div class="col-sm-8">
                                    <input type="text" name="minute" value="" class="vTextField"
                                           maxlength="64" required=""
                                           id="id_minute_1">
                                </div>
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Hour:</label>
                                <div class="col-sm-8">
                                    <input type="text" name="hour" value="" class="vTextField"
                                           maxlength="64" required=""
                                           id="id_hour_1">
                                </div>
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Day of week:</label>
                                <div class="col-sm-8">
                                    <input type="text" name="day_of_week" value=""
                                           class="vTextField" maxlength="64"
                                           required="" id="id_day_of_week_1">
                                </div>
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Day of month:</label>
                                <div class="col-sm-8">
                                    <input type="text" name="day_of_month" value=""
                                           class="vTextField" maxlength="64"
                                           required="" id="id_day_of_month_1">
                                </div>
                                <label class="col-sm-3 control-label"
                                       style="font-size: 12px;font-weight: 100">Month of year:</label>
                                <div class="col-sm-8">
                                    <input type="text" name="month_of_year" value=""
                                           class="vTextField" maxlength="64"
                                           required="" id="id_month_of_year_1">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-6">
                                    <button class="btn btn-primary" id="submit"><i
                                            class="fa fa-save"></i>&nbsp;保存
                                    </button>
                                    <button id="reset" type="reset" class="btn btn-primary"><i
                                            class="fa fa-repeat"></i>&nbsp;重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block javascript %}
    <script type="text/javascript">
        //重置 刷新页面
        $('#reset').click(function () {
            location.reload();
        });
        function get_plan() {
            $("#list").empty();
            $.ajax({
                type: "get",
                url: "/base/findata/",
                data: {
                    "type": "get_all_plan"
                },
                success: function (data) {
                    if (data == 'no') {
                        var error = $("#plan_error");
                        error.html("没有找到测试计划，请先添加！");
                        error.show();
                    } else {
                        $("#plan_error").hide();
                        var listdata = eval(data);
                        $(listdata).each(function (i, item) {
                            $("#list").append("<label class='checkbox-inline'><input type='checkbox' name='case_id' value=" + item.plan_id + ">" + item.plan_name + "</label>");
                        })
                    }
                },
                error: function () {
                    alert("获取用例失败");
                }
            });

        }

        function change_interval() {
            var period;
            $("#set_time_interval").show();
            var interval_ = $("#interval_").val();
            $.ajax({
                type: "get",
                url: "/base/findata/",
                data: {
                    "interval_id": interval_,
                    "type": "get_interval_or_id"
                },
                success: function (data) {
                    if (data == "no") {
                        alert("获取crontab数据失败！");
                    } else {
                        for (index in data) {
                            $("#id_every_1").val(data[index].every);
                            var option = $("#id_period_2");
                            option.attr("value", data[index].period);
                            if (data[index].period == "days") {
                                period = "天"
                            } else if (data[index].period == "hours") {
                                period = "时"
                            } else if (data[index].period == "minutes") {
                                period = "分"
                            }
                            else if (data[index].period == "seconds") {
                                period = "秒"
                            }
                            else if (data[index].period == "microseconds") {
                                period = "微秒"
                            }
                            option.html(period)

                        }
                    }

                }
            })
        }

        function change_crontab() {
            $("#set_crontab_minute").show();
            var crontab_ = $("#crontab_").val();
            $.ajax({
                type: "get",
                url: "/base/findata/",
                data: {
                    "crontab_id": crontab_,
                    "type": "get_crontab_or_id"
                },
                success: function (data) {
                    if (data == "no") {
                        alert("获取crontab数据失败！");
                    } else {
                        for (index in data) {
                            $("#id_minute_1").val(data[index].minute);
                            $("#id_hour_1").val(data[index].hour);
                            $("#id_day_of_week_1").val(data[index].day_of_week);
                            $("#id_day_of_month_1").val(data[index].day_of_month);
                            $("#id_month_of_year_1").val(data[index].month_of_year);
                        }
                    }

                }
            })
        }
        function execution() {
            var crontab_time = $("input[name='crontab_time']:checked").val();
            if (crontab_time == 1) {
                $("#interval_div").show();
                $("#crontab_div").hide();
                $("#set_time").hide();
                $("#interval").hide();
                $("#set_up_time").hide();
                $("#crontab_minute").hide();
                $("#set_crontab_minute").hide();
                $("#set_time_interval").hide();
            } else if (crontab_time == 2) {
                $("#interval_div").hide();
                $("#crontab_div").show();
                $("#set_time").hide();
                $("#interval").hide();
                $("#set_up_time").hide();
                $("#crontab_minute").hide();
                $("#set_crontab_minute").hide();
                $("#set_time_interval").hide();
            }

        }

        function crontab_div() {
            var crontab_div_time = $("input[name='crontab_div_time']:checked").val();
            if (crontab_div_time == 1) {
                $("#crontab_minute").show();
                $("#set_time").hide();
                $("#interval").hide();
                $("#set_up_time").hide();
                $("#set_crontab_minute").hide();
                $("#set_time_interval").hide();
            } else if (crontab_div_time == 2) {
                $("#set_up_time").show();
                $("#crontab_minute").hide();
                $("#set_time").hide();
                $("#interval").hide();
                $("#set_crontab_minute").hide();
                $("#set_time_interval").hide();
                var crontab = $("#crontab_").val();
                if (crontab == null) {
                    var error = $("#crontab_time_error");
                    error.html("未找到已设置时间，请选择其他选项！");
                    error.show();
                } else {
                    $("#crontab_time_error").hide()
                }

            }
        }

        function custom() {
            var task_time = $("input[name='task_time']:checked").val();
            if (task_time == 3) {
                $("#set_time").show();
                $("#interval").hide();
                $("#crontab_minute").hide();
                $("#set_crontab_minute").hide();
                $("#set_time_interval").hide();
            } else if (task_time == 4) {
                $("#interval").show();
                $("#set_time").hide();
                $("#crontab_minute").hide();
                $("#set_crontab_minute").hide();
                $("#set_time_interval").hide();
                var interval = $("#interval_").val();
                if (interval == null) {
                    var error = $("#interval_error");
                    error.html("未找到已设置时间，请选择其他选项！");
                    error.show();
                } else {
                    $("#interval_error").hide()
                }
            }
            else {
                $("#set_time").hide();
                $("#interval").hide();
                $("#crontab_minute").hide();
                $("#set_crontab_minute").hide();
                $("#set_time_interval").hide();
            }
        }
        function get_case() {
            var str = [];
            $("input[name='case_id']:checked").each(function (index, item) {

                if ($("input[name='case_id']:checked").length - 1 == index) {
                    str += $(this).val();
                } else {
                    str += $(this).val() + ",";
                }
            });
            return str
        }

        $("#submit").click(function () {
            var id_every, id_period, interval, crontab_, crontab;
            var task_name = $("#task_name").val();
            if (task_name == "") {
                var task_name_error = $("#task_name_error");
                task_name_error.html("项目名称不能为空！");
                task_name_error.show();
                $("#plan_error").hide();
                return false
            } else {
                $("#task_name_error").hide();
            }
            var plan_id = get_case();
            var task_id = $("#task_id").val();
            if (Object.keys(plan_id).length == 0) {
                var plan_error = $("#plan_error");
                plan_error.html("请选择测试计划！");
                plan_error.show();
                return false
            } else {
                $("#plan_error").hide();
                var status = $("input[name='status']:checked").val();
                var crontab_time = $("input[name='crontab_time']:checked").val();
                if (crontab_time == undefined) {
                    alert("请选择执行时间！");
                    return
                }
                if (crontab_time == 1) {
                    var task_time = $("input[name='task_time']:checked").val();
                    if (task_time == 3) {
                        id_every = $("#id_every").val();
                        id_period = $("#id_period").val();
                        if (id_every == "" || id_period == "") {
                            var error = $("#every_error");
                            error.html("Every 或者 Period 不能为空！");
                            error.show();
                            return false
                        } else {
                            $("#every_error").hide()

                        }

                    } else if (task_time == 4) {
                        id_every = $("#id_every_1").val();
                        id_period = $("#id_period_1").val();
                        {#                        if (id_every == "" || id_period == "") {#}
                        {#                            var error_ = $("#every_error_1");#}
                        {#                            error_.html("Every 或者 Period 不能为空！");#}
                        {#                            error_.show();#}
                        {#                            return false#}
                        {#                        } else {#}
                        {#                            $("#every_error_1").hide()#}
                        {##}
                        {#                        }#}
                        interval = $("#interval_").val();
                    }
                } else if (crontab_time == 2) {
                    var crontab_div_time = $("input[name='crontab_div_time']:checked").val();
                    if (crontab_div_time == undefined) {
                        alert("请选择Crontab时间！");
                        return
                    }
                    if (crontab_div_time == 1) {
                        var id_minute, id_hour, id_day_of_week, id_day_of_month, id_month_of_year;
                        id_minute = $("#id_minute").val();
                        id_hour = $("#id_hour").val();
                        id_day_of_week = $("#id_day_of_week").val();
                        id_day_of_month = $("#id_day_of_month").val();
                        id_month_of_year = $("#id_month_of_year").val();
                        if (id_minute.trim().length == 0 || id_hour.trim().length == 0 || id_day_of_week.trim().length == 0 || id_day_of_month.trim().length == 0 || id_month_of_year.trim().length == 0) {
                            alert("crontab输入框不能为空！");
                            return
                        }
                        crontab = {
                            "id_minute": id_minute,
                            "id_hour": id_hour,
                            "id_day_of_week": id_day_of_week,
                            "id_day_of_month": id_day_of_month,
                            "id_month_of_year": id_month_of_year
                        }
                    } else if (crontab_div_time == 2) {
                        crontab_ = $("#crontab_").val();
                        id_minute = $("#id_minute_1").val();
                        id_hour = $("#id_hour_1").val();
                        id_day_of_week = $("#id_day_of_week_1").val();
                        id_day_of_month = $("#id_day_of_month_1").val();
                        id_month_of_year = $("#id_month_of_year_1").val();
                        {#                        if (id_minute.trim().length == 0 || id_hour.trim().length == 0 || id_day_of_week.trim().length == 0 || id_day_of_month.trim().length == 0 || id_month_of_year.trim().length == 0) {#}
                        {#                            alert("crontab输入框不能为空！");#}
                        {#                            return#}
                        {#                        }#}
                        crontab = {
                            "id_minute": id_minute,
                            "id_hour": id_hour,
                            "id_day_of_week": id_day_of_week,
                            "id_day_of_month": id_day_of_month,
                            "id_month_of_year": id_month_of_year
                        }
                    }
                }
                $.ajax({
                    type: "post",
                    url: "/base/task_update/",
                    data: {
                        "task_time": task_time,
                        "task_name": task_name,
                        "id_every": id_every,
                        "id_period": id_period,
                        "interval": interval,
                        "crontab_": crontab_,
                        "crontab": JSON.stringify(crontab),
                        "crontab_time": crontab_time,
                        "crontab_div_time": crontab_div_time,
                        "plan_id": plan_id,
                        "status": status,
                        "task_id": task_id
                    },
                    success: function (data) {
                        if (data == "ok") {
                            alert("保存成功！");
                            window.location.replace('/base/task/?page={{ page }}')
                        } else {
                            alert(data)
                        }

                    }
                })
            }
        })
    </script>
{% endblock %}